#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from abc import ABCMeta, abstractmethod

from common.common_models import ActionResult, SubJobDetails
from common.const import SubJobStatusEnum
from common.number_const import NumberConst
from db2.comm.util.common_util import Db2CommonUtil


class Db2RestoreBase(metaclass=ABCMeta):
    """Db2恢复任务执行基类
    """
    def __init__(self, task_name, pid, job_id, sub_job_id, param_dict):
        self.task_name = task_name
        self.pid = pid
        self.job_id = job_id
        self.sub_job_id = sub_job_id
        self.param_dict = param_dict
        self.sub_job_detail = SubJobDetails(
            taskId=self.job_id, subTaskId=self.sub_job_id, progress=NumberConst.ONE,
            logDetail=list(), taskStatus=SubJobStatusEnum.RUNNING.value)

    @abstractmethod
    def allow_restore_in_local_node(self):
        """是否允许本地运行恢复"""
        pass

    @abstractmethod
    def exec_restore_pre_job(self):
        """恢复前置"""
        pass

    @abstractmethod
    def exec_restore(self):
        """恢复任务"""
        pass

    @abstractmethod
    def exec_restore_post_job(self):
        """恢复后置"""
        pass

    @abstractmethod
    def report_progress(self):
        """上报进度"""
        pass

    @abstractmethod
    def output_action_result(self, action_ret: ActionResult):
        """输出任务结果到结果文件"""
        Db2CommonUtil.output_action_result(
            self.pid, action_ret.code, body_err=action_ret.body_err, message=action_ret.message,
            err_params=action_ret.body_err_params)

    def exec_restore_gen_sub_job(self):
        pass
